/*
 * Created on 23-jul-2005
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.mushroomdb.engine.statistics;

/**
 * @author Admin
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class MeanCalculator {

	/**
	 * 
	 * @param oldMean
	 * @param newSize
	 * @param newValue
	 * @return Devuelve la nueva media con respecto a una anterior y a la cantidad de valores.
	 */
	public static double calculateMean(double oldMean, long newSize, double newValue) {
		double actualSize = (double)newSize;
		double oldSum = oldMean * (actualSize - 1);
		double newSum = oldSum + newValue;
		double newMean = newSum / actualSize;
		return newMean;
	}
}
